﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VMS.FTS.APPPUSH.LOGGER
{
    public abstract class ILogable
    {
        protected string LOG_TAG;
        protected void Log(string message, LOG_LEVEL level)
        {
            Logger.Instance.append(LOG_TAG, message, level);
#if DEBUG
            LOG_LEVEL baseLevel = LOG_LEVEL.OFF;
            if (level > baseLevel)
            ///Debug.WriteLine (LOG_TAG, message, level);
            if (level == LOG_LEVEL.ERROR)
                Console.ForegroundColor = ConsoleColor.Red;
            else if(level == LOG_LEVEL.INFO)
                Console.ForegroundColor = ConsoleColor.Yellow;
            else 
                Console.ForegroundColor = ConsoleColor.White;
            
            
            Console.Out.WriteLine(DateTime.Now.ToString("hh:mm:ss") +
                        " | " + level +
                        " | " + LOG_TAG +
                        " | " + message);
#endif
        }

        protected void LogException(Exception ex)
        {
            string message = "Exception:\n" + ex.Message + "\nStack trace: " + ex.StackTrace;
            Log(message, LOG_LEVEL.ERROR);
#if DEBUG
                Console.ForegroundColor = ConsoleColor.Red;
            Console.Out.WriteLine(DateTime.Now.ToString("hh:mm:ss") +
                        " | " + "ERROR" +
                        " | " + LOG_TAG +
                        " | " + message);
#endif
        }
    }
}
